package bible.sunflower.util.java;

import java.lang.reflect.Method;

public class ClassUtil {
	
	
	public static Object invokeStaticMethod(String className, String methodName, Object[] params){
		Object result = null;
		try {
			Class clazz = Class.forName( className );
			Class[] paramClazz = new Class[params.length];
			for(int i =0; i < params.length; i++){
				paramClazz[i] = params[i].getClass();
			}
			Method method = clazz.getMethod( methodName, paramClazz );
			result = method.invoke(null, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static Object invokeDynamicMethod(Object obj, String methodName, Object[] params){
		Object result = null;
		try {
			Class clazz = obj.getClass();
			Class[] paramClazz = new Class[params.length];
			for(int i =0; i < params.length; i++){
				paramClazz[i] = params[i].getClass();
			}
			Method method = clazz.getMethod( methodName, paramClazz );
			result = method.invoke(obj, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	
}
